package com.example.sdbtspringboot.exception;

import com.example.sdbtspringboot.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.transform.Source;

/**
 * @Description: 自定义异常类
 * @Author: cao
 * @Date: 2024/5/26 22:58
 */
@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result serviceException(ServiceException e){

        return Result.error(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result globalException(ServiceException e){
        e.printStackTrace();
        return Result.error("500","系统错误");
    }

}
